//Ta Duc Viet
//Tinh sin - cos theo do
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
long double ldabs( long double a){
     if ( a < 0) return - a;
     else return a;
     }
     
long double sin( float x, long double delta){ //delta: sai so
    long double temp, sin;
    temp = sin = x;
    for ( int i = 3; ldabs(temp) > delta; i = i + 2){
        temp = - ( temp * x * x ) / ( i * ( i - 1 ) );
        sin = sin + temp;
    }
    return sin;
}

long double cos( float x, long double delta){
    long double cos, temp;
    cos = temp = 1;
    for ( int i = 2; ldabs(temp) > delta; i = i + 2){
        temp = - ( temp * x * x ) / ( i * ( i - 1 ) );
        cos = cos + temp;
    }
    return cos;
}

int main(){
    const double pi = 3.14;
    float x;
    long double delta;
    cout << "x = ";
    cin >> x;
    x = x * pi / 180;
    cout << "Sai so:";
    cin >> delta;
    int size = 0;
    for ( double i = 0; i < 20; i++){
        if ( delta * pow ( 10, i) > 1 ) {
             size = i - 1;
             break;
             }
             }
    cout << fixed << setprecision (size + 1);
    cout << "Sin (x) = " << sin( x, delta) << endl;
    cout << "Cos (x) = " << cos( x, delta) << endl;
    system ("pause");
    return 0;
}
